import { useState, useEffect } from 'react'
import { Table ,Switch ,Popconfirm,Button,message} from 'antd'
import Found from './sevices/api'
import style from './style.module.scss'
const {changeimg} = style
const APP = () => {

  const [list, setList] = useState([])
  const getFoundList = async () => {
    let res = await Found['getList']()
    console.log(res);
    setList(res.data)
  }
  const confirm=async(id)=>{
      let res = await Found['delList'](id)
      console.log(res);
      getFoundList()
  }
  const cancel = () => {
    message.error('取消删除');

  }
const changeFlag=async(row)=>{
    let res = await Found ['changeList']({id:row.id,flag:row.flag})
    console.log(res);
    getFoundList()
}
    useEffect(() => {getFoundList()}, [])
    const columns = [{
      title: "序号",
      render: (_, row, index) => <span>{index + 1}</span>
    },
    {
      title: "图片",
      render: (_, row, index) => <img src={row.img} />
    }
      ,
    {
      title: "地址",
      render: (_, row, index) => <span>{row.address}</span>
    },
    {
      title: "评价",
      render: (_, row, index) => <span>{row.appraise}</span>
    },
    {
      title: "用户id",
      render: (_, row, index) => <span>{row.userid}</span>
    },
    {
      title: "是否展示",
      render: (_, row, index) => <Switch defaultChecked={row.flag} onChange={()=>changeFlag(row)} ></Switch>
    },
    {
      title: "点赞数",
      render: (_, row, index) => <span>{row.Likenum}</span>
    },
   
       {
      title: "操作",
      render: (_, row, index) => <div><Popconfirm

        title="删除？"
        description="确定要删除？"
        onConfirm={() => confirm(row.id)}
        onCancel={cancel}
        okText="是"
        cancelText="否"
      >
        <Button >删除</Button>

      </Popconfirm>
        {/* <Button onClick={() => show(row)}>编辑</Button> */}

      </div>
    }

    ]
    return (<>
      <Table rowKey='id' className={changeimg} columns={columns} dataSource={list} />

    </>)
}

export default APP